package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.query.AttendanceQueryObject;
import cn.wolfcode.crm.service.IAttendanceService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("attendance")
public class AttendanceController {


    @Autowired
    private IAttendanceService attendanceService;

    @RequestMapping("")
    public String attendancePage(){
        return "/attendance/list";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(AttendanceQueryObject qo){
        return  attendanceService.query(qo);
    }


    @RequestMapping("signIn")
    @ResponseBody
    public JsonResult signIn() {
        JsonResult result = new JsonResult();
        try {
            attendanceService.signIn();
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("签到失败");
        }
        return result;
    }

    @RequestMapping("signOut")
    @ResponseBody
    public JsonResult singOut(){
        JsonResult result = new JsonResult();
        try {
            attendanceService.signOut();
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("签退失败");
        }
        return result;
    }


}
